<template>
  <div>
    <el-form
      label-width="240px"
    >
      <el-form-item label="accessKeyId">
        <el-input v-model="companyConfigAliSms.accessKeyId"/>
      </el-form-item>
      <el-form-item label="accessKeySecret">
        <el-input v-model="companyConfigAliSms.accessKeySecret"/>
      </el-form-item>
      <el-form-item :label="$t('sms')+$t('sign')">
        <el-input v-model="companyConfigAliSms.signName"/>
      </el-form-item>
      <el-form-item :label="$t('sms')+$t('warn')+$t('template')+$t('id')">
        <el-input v-model="companyConfigAliSms.warnTemplateId"/>
      </el-form-item>
      <el-form-item :label="$t('save')">
        <el-button type="primary" @click="updateCompanyConfigAliSms">{{ $t('confirm') }}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { successNotice } from '@/util/common'
import { getCompanyConfigAliSms, updateCompanyConfigAliSms } from '@/api/iot/iotCompanyConfigAliSmsApi'

export default {
  name: 'IotAliSms',
  props: {
    companyId: {
      type: Number,
      default: null
    }
  },
  data() {
    return {
      companyConfigAliSms: {}
    }
  }, created() {
    this.getCompanyConfigAliSms()
  }, methods: {
    getCompanyConfigAliSms() {
      getCompanyConfigAliSms({
        companyId: this.companyId
      }).then(res => {
        const { data } = res
        if (data) {
          this.companyConfigAliSms = data
        }
      })
    },
    updateCompanyConfigAliSms() {
      updateCompanyConfigAliSms({
        ...this.companyConfigAliSms,
        companyId: this.companyId
      }).then(res => {
        const { code } = res
        if (code === '200') {
          successNotice(this)
          this.getCompanyConfigAliSms()
        }
      })
    }
  }
}
</script>

